package br.com.lh.urabuilder.util.pointchooser
{
	import br.com.lh.urabuilder.view.ActionComponent;
	
	import flash.geom.Point;
	
	public class OneComponentPointChooser implements IPointChooser
	{
		
		private var component:ActionComponent;
		private var point:Point;
		
		public function OneComponentPointChooser(component:ActionComponent,fixedPoint:Point){
			this.component = component;
			this.point = fixedPoint;
		}

		public function get pointArray():Array
		{
			var isBelow:Boolean=isValueGreater(point.y, component.y);
			var isRight:Boolean = isValueGreater(point.x,component.x);
			var ratio:Number = getRatio();
			if (Math.abs(ratio) > 1){	
				return yGreater(isBelow,isRight);
			}else{
				return xGreater(isBelow,isRight);
			}
			return new Array();
		}
		
		
		private function yGreater(isBelow:Boolean,isRight:Boolean):Array{
			if (isBelow){
				return [component.getBottomPoint(),point];
			}else{
				return [component.getTopPoint(),point];
			}
			
		}
		private function xGreater(isBelow:Boolean,isRight:Boolean):Array{
			if (isRight){
				return [component.getRightPoint(),point];
			}else{
				return [component.getLeftPoint(),point];
			}
		}
		
		private function isValueGreater(endValue:Number,startValue:Number):Boolean{
			return endValue >= startValue;
		}
		
		private function getRatio():Number{
			var yDelta:Number = point.y - component.y;
			var xDelta:Number = point.x - component.x;
			return yDelta/xDelta;
		}

		
	}
}